package com.dmy.component;

import com.dmy.config.GlobleConfig;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class MJPanel extends JPanel {


    private java.util.List<Snake> snakes; // 蛇
    private Food food;
    public MJPanel() {
        snakes = new ArrayList<Snake>();
        food = new SimpleFood(this);
    }
    public final java.util.List<Snake> addSnake(Snake snake){
        snakes.add(snake);
        return snakes;
    }
    public java.util.List<Snake> getSnakes(){
        return snakes;
    }
    /**
     *  绘画组件
     * @param g
     */
    @Override
    public void paint(Graphics g) {
        Graphics2D gg = (Graphics2D)g;
        gg.fillRect(0,0, GlobleConfig.WINDOW_WIDTH,GlobleConfig.WINDOW_HEIGHT);
        snakes.forEach(s->s.paint((Graphics2D)g));
        food.paint((Graphics2D)g);
    }
}
